package com.colorlight.cloud.complete.entity.enumerate;

/**
 * @author Demon
 * @date 6/5/2024  上午9:37
 */

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * proto方法类型
 */
@Getter
public enum ParamIndexEnum implements EnumTrans<CompleteEntity.ParamIndexEnum, ParamIndexEnum> {
	/**
	 * 设置所有
	 * 服务器地址
	 * 心跳间隔 单位：millisecond
	 * 服务器端口号
	 * 屏体名称
	 * 	设备型号
	 * 	三元组-设备名称
	 * 	三元组-产品名称
	 * 	三元组-设备密钥
	 * 	监控需要上报数据的类型
	 * 	上报频率
	 * 	接收卡监控上报项
	 */
	
	ALL(CompleteEntity.ParamIndexEnum.ALL),
	SERVER_ADDRESS(CompleteEntity.ParamIndexEnum.SERVER_ADDRESS),
	SERVER_PORT(CompleteEntity.ParamIndexEnum.SERVER_PORT),
	HB_INTERVAL(CompleteEntity.ParamIndexEnum.HB_INTERVAL),
	SCREEN_NAME(CompleteEntity.ParamIndexEnum.SCREEN_NAME),
	SN(CompleteEntity.ParamIndexEnum.SN),
	MODEL(CompleteEntity.ParamIndexEnum.MODEL),
	DEVICE_NAME(CompleteEntity.ParamIndexEnum.DEVICE_NAME),
	PRODUCT_KEY(CompleteEntity.ParamIndexEnum.PRODUCT_KEY),
	DEVICE_SECRET(CompleteEntity.ParamIndexEnum.DEVICE_SECRET),
	MONITOR_TYPE(CompleteEntity.ParamIndexEnum.MONITOR_TYPE),
	INTERVALS(CompleteEntity.ParamIndexEnum.INTERVALS),
	RECEIVER_MONITOR(CompleteEntity.ParamIndexEnum.RECEIVER_MONITOR);
	
	
	private final Integer id;
	private final String name;
	private final CompleteEntity.ParamIndexEnum paramIndexEnum;
	private static final long serialVersionUID = 987654321987654321L;
	
	ParamIndexEnum(CompleteEntity.ParamIndexEnum paramIndexEnum) {
		this.id = paramIndexEnum.getNumber();
		this.name = paramIndexEnum.name();
		this.paramIndexEnum = paramIndexEnum;
	}
	
	/**
	 * @param paramIndexEnum
	 * @return 对应的类型
	 */
	public static ParamIndexEnum getScheduleTypeStruct(CompleteEntity.ParamIndexEnum paramIndexEnum) {
		Objects.requireNonNull(paramIndexEnum, "ParamIndexEnum can not be null.");
		return Arrays.stream(ParamIndexEnum.values())
				.filter(e -> e.name.equals(paramIndexEnum.name()))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	@Override
	public CompleteEntity.ParamIndexEnum toProto() {
		return this.paramIndexEnum;
	}
	
	@Override
	public ParamIndexEnum formProto(CompleteEntity.ParamIndexEnum paramIndexEnum) {
		return getScheduleTypeStruct(paramIndexEnum);
	}
}
